package com.vividsolutions.jts.addons.simulate;

import java.math.BigDecimal;
import java.util.Arrays;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.triangulate.quadedge.QuadEdge;

public class Gwt {

	static GeometryFactory gf = new GeometryFactory();

	public static long doubleToLongBits(double x) {
		long f = BigDecimal.valueOf(x).longValue();
		return f;
	}

	public static double longBitsToDouble(long commonBits) {
		double d = BigDecimal.valueOf(commonBits).doubleValue();
		return d;
	}

	public static Object clone(Object obj) {
		Object ret = null;
		if (obj instanceof Coordinate) {
			ret = new Coordinate((Coordinate) obj);
		} else if (obj instanceof Geometry) {
			Geometry geom = (Geometry) obj;
			ret = gf.createGeometry(geom);
		} else if (obj instanceof QuadEdge[]) {
			QuadEdge[] ls = (QuadEdge[]) obj;
			return Arrays.asList(ls).toArray();
		} else {
			System.out.println("haven't implement for "
					+ obj.getClass().getName());
		}

		return ret;
	}

	public static boolean isWhitespace(char charAt) {
		boolean isWhiteSpace = (charAt == ' ');
		return isWhiteSpace;
	}

}
